/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.config;

import com.comac.ins.isfd.domain.vo.IsfdModelManagementOriginalPartVo;
import com.comac.ins.isfd.mapper.IsfdModelManagementOriginalPartMapper;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 模型管理原始装机清单config
 */
@Configuration
public class IsfdModelManagementOriginalPartConfig {

    @Autowired
    private IsfdModelManagementOriginalPartMapper isfdModelManagementOriginalPartMapper;

    private final static List<IsfdModelManagementOriginalPartVo> ORIGINAL_PART_VO_LIST = new ArrayList<>();


    @PostConstruct
    private void initVoList() {
        List<IsfdModelManagementOriginalPartVo> allVos = isfdModelManagementOriginalPartMapper.selectVoList();
        ORIGINAL_PART_VO_LIST.clear();
        ORIGINAL_PART_VO_LIST.addAll(allVos);
    }

    /**
     * 根据部段名和零件号查询列表数据
     */
    public List<IsfdModelManagementOriginalPartVo> getOriginalPartVoList(String modelNumber, List<String> sectionNameList, String originalPartNumber) {
        return ORIGINAL_PART_VO_LIST.stream()
            .filter(vo ->
                modelNumber.equals(vo.getModelNumber()) &&
                    sectionNameList.contains(vo.getSectionName()) &&
                    originalPartNumber.equals(vo.getPartNumber()))
            .collect(Collectors.toList());
    }
}
